<template>
  <div>
    <el-form ref="form" :model="form" label-width="100px" size="medium">
      <el-row>
        <el-col :span="6">
          <el-form-item label="病历号">
            <el-input v-model="form.id" :span="10" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="姓名">
            <el-input v-model="form.name" :span="10"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="性别">
            <el-select v-model="form.gender" placeholder="请选择">
          <el-option
            v-for="item in options.genderOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="年龄">
            <el-input v-model="form.age" :span="10"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
        <el-row>
        <el-col :span="7">
          <el-form-item label="出生日期">
            <div class="block">
    <el-date-picker
      v-model="form.birthday"
      type="date"
      value-format="yyyy-MM-dd"
      placeholder="选择出生日期">
    </el-date-picker>
  </div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="身份证号">
            <el-input v-model="form.idno" :span="10"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="家庭住址">
            <el-input v-model="form.address" :span="10"></el-input>
          </el-form-item>
        </el-col>
        
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="挂号级别">
            <el-select @change="registLevelChange" v-model="form.registLevelId" placeholder="请选择挂号级别">
          <el-option
            v-for="item in options.registLevelOptions"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="挂号科室">
              <el-select @change="deptIdChange()" v-model="form.deptId" placeholder="请选择挂号科室">
          <el-option
            v-for="item in options.deptOptions"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="挂号医生">
              <el-select v-model="form.doctorId" placeholder="请选择挂号医生">
          <el-option
            v-for="item in options.doctorOptions"
            :key="item.id"
            :label="item.realname"
            :value="item.id">
          </el-option>
        </el-select>
          </el-form-item>
        </el-col>
        
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="看诊日期">
            <div class="block">
    <el-date-picker
      v-model="form.visittime"
      type="date"
      value-format="yyyy-MM-dd"
      placeholder="选择看诊日期">
    </el-date-picker>
  </div>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="是否要病历本">
            <el-radio-group v-model="form.book">
        <el-radio :label="1">是</el-radio>
        <el-radio :label="0">否</el-radio>
      </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="应收金额">
            <el-input v-model="form.fee" :span="10"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
        <el-button type="primary" @click="save()">保存数据</el-button>
      </el-form-item>
        </el-col>
        
      </el-row>
      
    </el-form>
    <el-row>
      <el-col :span="24">已挂号列表</el-col>
    </el-row>
    <RegistList :key="sonRefresh"></RegistList>
  </div>
</template>

<script>
import RegistList from '@/views/regist/registlist'
export default {
  name: "Regist",
  data() {
    return {
      form: {
        registLevelId: null,
        deptId: null,
        doctorId: null,
        fee: 0,
        book: 1,
        name: '',
        gender: 1,
        age: 0,
        idno: null,
        address: null,
        visittime: null
      },
      options:{
            registLevelOptions:[],
            deptOptions:[],
            doctorOptions:[],
            genderOptions:[{
                label: '男',
                value: 1
            },
            {
                label: '女',
                value: 2
            }]
        },
      sonRefresh: 1
    }
  },
  methods: {
      getRegistLevel()
      {
          this.axios.get('/regist-level/list',response => {
              this.options.registLevelOptions = response.obj
          },{active:1,withPage:0})
      },
      getDepartment()
      {
          this.axios.get('/department/list',response => {
              this.options.deptOptions = response.obj
          },{active:1,withPage:0,type:1})
      },
      queryDoctor()
      {
          this.form.doctorId = null
          if(this.form.registLevelId && this.form.deptId)
          {
              this.axios.get("/ums-user/list",respone => {
                this.options.doctorOptions=respone.obj
              },{
                  deptId:this.form.deptId,
                  registLevel:this.form.registLevelId,
                  withPage:0,
                  active:1
              })
          }
      },
      save(){
          this.axios.post('/register/regist',response => {
            if(response.code===200)
            {
              this.sonRefresh++
            }
        },this.form)
      },
      deptIdChange(){
          this.queryDoctor()
      },
      registLevelChange(){
          this.queryDoctor()
          this.fee()
      },
      fee(){
          for(let i=0;i<this.options.registLevelOptions.length;i++)
          {
              if(this.options.registLevelOptions[i].id == this.form.registLevelId)
              {
                  this.form.fee = this.options.registLevelOptions[i].fee
                  if(this.form.book == 1)
                  {
                      this.form.fee = 1 + this.form.fee
                  }
                  break
              }
          }
      },
      getNextId()
      {
        this.axios.get('/register/next-id',response => {
          this.form.id = response.obj
        })
      }
  },
  created(){
      this.getRegistLevel()
      this.getDepartment()
      this.getNextId()
  },
  components:{
    RegistList
  }
}
</script>

<style>
</style>